//
//  AlertTip.m
//  CrmIpad
//
//  Created by xiewuyuan on 14-6-6.
//  Copyright (c) 2014年 authur.xie. All rights reserved.
//

#import "AlertUtil.h"


@implementation AlertUtil

+ (void)alertLightSuccess:(NSString *)content {
    [self alertLightSuccess:content toView:nil withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertLightSuccess:(NSString *)content toView:(UIView *)view withOffsetX: (float)xOffset withOffsetY:(float)yOffset {
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.offset = CGPointMake(xOffset, yOffset);
    //hud.contentColor = [UIColor whiteColor];
    hud.detailsLabel.text = content;
    hud.minSize = CGSizeMake(180, 120);
    hud.bezelView.color = [UIColor colorWithWhite:1 alpha:0.7];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"success.png"]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // [hud setOpaque:NO];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:2];
    //[hud hide:YES afterDelay:3];
}


+ (void)alertSuccess:(NSString *)content {
    [self alertSuccess:content toView:nil withOffsetX:0.0 withOffsetY:0.0];
}


+ (void)alertSuccess:(NSString *)content toView:(UIView *)view withOffsetX: (float)xOffset withOffsetY:(float)yOffset {
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.offset = CGPointMake(xOffset, yOffset);
    hud.contentColor = [UIColor whiteColor];
    hud.detailsLabel.text = content;
    hud.detailsLabel.font = [UIFont systemFontOfSize:16];
    hud.minSize = CGSizeMake(180, 120);
    hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.7];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 设置图片
    UIView * customView = [[UIView alloc] init];
    UIImageView * imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"success.png"]]];
    [customView addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
    }];
    hud.customView = customView;
    //[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"success.png"]]];
    
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // [hud setOpaque:NO];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:2];
    //[hud hide:YES afterDelay:3];
}


+ (void)alertMessage:(NSString *)content toView:(UIView *)view withOffsetX: (float)xOffset withOffsetY:(float)yOffset {
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.offset = CGPointMake(xOffset, yOffset);

    hud.contentColor = [UIColor whiteColor];
    hud.detailsLabel.text = content;
//    hud.minSize = CGSizeMake(180, 100);
    hud.detailsLabel.font = [UIFont systemFontOfSize:16];
    hud.bezelView.color = [UIColor colorWithWhite:0.5 alpha:0.7];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 设置图片
//    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"message.png"]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
   // [hud setOpaque:NO];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1];
    //[hud hide:YES afterDelay:1];
}

+ (void)alertMessage:(NSString *)content toView:(UIView *)view {
    [self alertMessage:content toView:view withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertMessage:(NSString *)content {
    [self alertMessage:content toView:nil withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertWarning:(NSString *)content toView:(UIView *)view withOffsetX: (float)xOffset withOffsetY:(float)yOffset {
    if (view == nil) { view = [[UIApplication sharedApplication].windows lastObject]; };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.offset = CGPointMake(xOffset, yOffset);
    hud.contentColor = [UIColor whiteColor];
    hud.detailsLabel.text = content;
    hud.minSize = CGSizeMake(180, 100);
    hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.7];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"warning.png"]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1];
}

+ (void)alertWarning:(NSString *)content toView:(UIView *)view {
    [self alertWarning:content toView:view withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertWarning:(NSString *)content {
    [self alertWarning:content toView:nil withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertError:(NSString *)content toView:(UIView *)view withOffsetX: (float)xOffset withOffsetY:(float)yOffset {
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.offset = CGPointMake(xOffset, yOffset);
    hud.contentColor = [UIColor whiteColor];
    hud.detailsLabel.text = content;
    hud.detailsLabel.font = [UIFont systemFontOfSize:16];
    hud.minSize = CGSizeMake(180, 120);
    hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.7];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 设置图片
    UIView * customView = [[UIView alloc] init];
    UIImageView * imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"error.png"]]];
    [customView addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
    }];
    hud.customView = customView;
    //[[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"AlertUtil.bundle/%@", @"success.png"]]];
    
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // [hud setOpaque:NO];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:2];
    //[hud hide:YES afterDelay:3];
}

+ (void)alertError:(NSString *)content toView:(UIView *)view {
    [self alertError:content toView:view withOffsetX:0.0 withOffsetY:0.0];
}

+ (void)alertError:(NSString *)content {
    [self alertError:content toView:nil withOffsetX:0.0 withOffsetY:0.0];
}

+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) { view = [[UIApplication sharedApplication].windows lastObject]; };
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    //hud.dimBackground = YES;
    return hud;
}

+ (MBProgressHUD *)showMessage:(NSString *)message {
    return [self showMessage:message toView:nil];
}

@end
